﻿using System;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class controls_Slider : System.Web.UI.UserControl
{

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack)
        {
            Trace.Warn("!2"); 
            Panel[] array = sliderImages.Controls.OfType<Panel>().ToArray();
            for (int i = 0; i < array.Length; i++)
                if (i == FirstImage) array[i].CssClass += " active";
                else array[i].CssClass = "item";
        }
        else
        {
            FirstImage = 0;
        }
    }

    public int FirstImage
    {
        get
        {
            object _firstImage = ViewState["FirstImage"];
            if (_firstImage != null)
            {
                return (int)_firstImage;
            }
            else
            {
                return 0;
            }
        }
        set
        {
            ViewState["FirstImage"] = value;
        }
    }
    protected void sliderLeft_Click(object sender, EventArgs e)
    {   
        FirstImage = (FirstImage - 1);
        if (FirstImage < 0)
            FirstImage = sliderImages.Controls.OfType<Panel>().Count() - 1;
    }
    protected void sliderRight_Click(object sender, EventArgs e)
    {
        Trace.Warn("!"); 
        FirstImage = (FirstImage + 1) % (sliderImages.Controls.OfType<Panel>().Count());
    }
}